package com.thread.async;

import java.util.concurrent.locks.LockSupport;

/**
 * @author wangyingjie
 * @date
 * @remark
 */
public class SupportLockDemo {
    private static Object obj = new Object();



    public static class changeObjecthread extends Thread{
        public changeObjecthread(String name) {
            super.setName(name);
        }

        @Override
        public void run() {
            System.out.println(this.getName()+"运行了。。。");
            synchronized (obj){
                System.out.println(this.getName()+"进同步,阻塞。。");
                LockSupport.park();
                if (this.isInterrupted()){
                    System.out.println(this.getName()+"被中断了。。");
                }
            }
//            for (int i = 0; i < 1000; i++) {
//                int j = i;
//            }
            System.out.println(this.getName()+"执行结束。。");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        changeObjecthread t1 = new changeObjecthread("t1");
        changeObjecthread t2 = new changeObjecthread("t2");
        t1.start();
        Thread.sleep(100);
        t2.start();
        t1.interrupt();
        LockSupport.unpark(t2);
    }

}
